package dbutilsDemo;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;

/**
 * commons-dbutils + c3p0
 * 
 * @author zhaigx
 * @date 2012-12-16
 */
public class DbUtilsDemo implements Runnable {

	// static DataSource ds = DruidConnPool.getDs();
	// static DataSource ds = JDBCUtils.getDs();
	public static void main(String[] args) {
		test3();
	}

	private static void test3() {
		String sql = "select certificate,contactman from m_customer00 ";

		System.out.println("");

	}

	private static void test2() {
		// String sql =
		// "update B_BROADBAND_USER00 set downbandwidth=?,moddate=?,modoperator=? where username=?";
		// List<Object[]> list = new ArrayList<Object[]>();
		// Object[] u1 = { Integer.valueOf(10),
		// new Timestamp(new Date().getTime()), "zgx1", "030207" };
		// Object[] u2 = { Integer.valueOf(11),
		// new Timestamp(new Date().getTime()), "zgx2", "030207" };
		// Object[] u3 = { Integer.valueOf(12),
		// new Timestamp(new Date().getTime()), 33, "zgx3", "030207" };
		// Object[] u4 = { Integer.valueOf(13),
		// new Timestamp(new Date().getTime()), "zgx4", "030207" };
		// Object[] u5 = { "14", new Timestamp(new Date().getTime()), "zgx5",
		// "030207" };
		// Object[] u6 = { Integer.valueOf(15), new Date(), "zgx6", "030207" };
		// String sql =
		// "insert into mon_type(type,typename,interval) values(?,?,?)";

		// String sql =
		// "update mon_type set type=?,typename=?,interval=? where type=?";
		// Object[] u1 = { Integer.valueOf(1), "test11", Integer.valueOf(3), };
		// Object[] u2 = { Integer.valueOf(2), "test22", Integer.valueOf(3),
		// new Date() };
		// Object[] u3 = { Integer.valueOf(3), "test33", Integer.valueOf(3), 3
		// };
		// Object[] u4 = { Integer.valueOf(4), "test44", Integer.valueOf(3), 4
		// };

		String sql = "select 1 from mon_type where type=?";
		Object[] u1 = { Integer.valueOf(1) };
		Object[] u2 = { Integer.valueOf(5) };
		Object[] u3 = { Integer.valueOf(3) };
		Object[] u4 = { Integer.valueOf(7) };
		List<Object[]> list = new ArrayList<Object[]>();
		list.add(u1);
		list.add(u2);
		list.add(u3);
		list.add(u4);
		Connection conn = JDBCUtils.getConn();
		SqlUtil.batchQuery(sql, list, conn);

	}

	private static void test1() {
		// String sql =
		// "update B_BROADBAND_USER00 set downbandwidth=?,moddate=?,modoperator=? where username=?";
		// List<Object[]> list = new ArrayList<Object[]>();
		// Object[] u1 = { Integer.valueOf(10),
		// new Timestamp(new Date().getTime()), "zgx1", "wsba01160" };
		// Object[] u2 = { Integer.valueOf(11),
		// new Timestamp(new Date().getTime()), "zgx2", "13908703365" };
		// Object[] u3 = { Integer.valueOf(12),
		// new Timestamp(new Date().getTime()), "zgx3", "yxjccljl" };
		// Object[] u4 = { Integer.valueOf(13),
		// new Timestamp(new Date().getTime()), "zgx4", "kdjs0908" };
		// Object[] u5 = { Integer.valueOf(14),
		// new Timestamp(new Date().getTime()), "zgx5", "z21l98888" };
		// Object[] u6 = { Integer.valueOf(14),
		// new Timestamp(new Date().getTime()), "zgx6", "z2ddd1l98888" };
		String sql = "insert into mon_type(type,typename,interval)";
		Object[] u1 = { 1, "test1", 3 };
		Object[] u2 = { 1, "test1", 3 };
		Object[] u3 = { 1, "test1", 3 };
		Object[] u4 = { 1, "test1", 3 };
		List<Object[]> list = new ArrayList<Object[]>();
		list.add(u1);
		list.add(u2);
		list.add(u3);
		list.add(u4);
		Connection conn = JDBCUtils.getConn();
		// SqlUtil.batchUpdate(sql, list, conn);
		QueryRunner qr = new QueryRunner();
		Object[][] params = { u1, u2, u3, u4 };
		try {
			int[] r = qr.batch(conn, sql, params);
			System.out.println(Arrays.toString(r));
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	private static void test0() {
		DbUtilsDemo demo = new DbUtilsDemo();
		for (int j = 0; j < 2; j++) {
			for (int i = 0; i < 10; i++) {

				Thread thread = new Thread(demo);
				thread.start();
				// try {
				// Thread.sleep(1000);
				// } catch (InterruptedException e) {
				// // TODO Auto-generated catch block
				// e.printStackTrace();
				// }
			}
		}
	}

	private static void test() {
		BroadbandUserService2 service = Factory.getInstance().getUserService();
		service.updateUser();
	}

	@Override
	public void run() {
		test();
	}
}
